<template>
	<view class="bottomBtn">
		<view class="row" @click="onOperation(1,info.is_like == 1 )">
			<image src="http://tuzhuang-1304727035.file.myqcloud.com/20211213/YDvHTYdV40Mr0Mes4DJXg1jvsLNjQROx8BQKkLFq.png" mode="scaleToFill"  v-if="info.is_like == 1"></image>
			<image src="http://tuzhuang-1304727035.file.myqcloud.com/20211213/lSK7pXE39wJeV96F13U88TjgX1x27kMYFehTvmxP.png" mode="scaleToFill" v-else></image>
			{{objInfo.like ? objInfo.like :  0}}
		</view>
		<view class="row" @click="onOperation(2,objInfo.is_collect == 1 )">
			<image src="http://tuzhuang-1304727035.file.myqcloud.com/20211213/GKE0onhRAublBcECEMLlS2nmNNbLUClCpsTf1UVq.png" mode="scaleToFill" v-if="objInfo.is_collect == 1"></image>
			<image src="http://tuzhuang-1304727035.file.myqcloud.com/20211213/UqCVIBO5Y4YcmClAqexlQz6jFzsfp7sT3HQv0Jm9.png" mode="scaleToFill"  v-else></image>
			{{objInfo.collect ? objInfo.collect :  0}}
		</view>
		<!-- <view  @click="onOperation(3)">
			<image src="http://tuzhuang-1304727035.file.myqcloud.com/20211213/y3es35peNBbC1bpkQQTfqsMPEjsLdlHTbJW14Nr9.png" mode=""></image>
			{{objInfo.transmit ? objInfo.transmit :  0}}
		</view> -->
		<!-- #ifdef MP-WEIXIN  -->
		<button  class="row row2" open-type="share">
			<image src="http://tuzhuang-1304727035.file.myqcloud.com/20211213/y3es35peNBbC1bpkQQTfqsMPEjsLdlHTbJW14Nr9.png" mode=""></image>
			{{objInfo.transmit ? objInfo.transmit :  0}}
		</button>
		<!-- #endif -->
		<!-- #ifndef MP-WEIXIN  -->
		<view class="row" @click="onOperation(3)">
			<image src="http://tuzhuang-1304727035.file.myqcloud.com/20211213/y3es35peNBbC1bpkQQTfqsMPEjsLdlHTbJW14Nr9.png" mode=""></image>
			{{objInfo.transmit ? objInfo.transmit :  0}}
		</view>
		<!-- #endif -->
	</view>
</template>

<script>
	import {setLikeCollection,setAddShare} from "@/utils/postRequest.js"
	export default {
		props:{
			info:{
				type:Object,
				default:()=>{}
			},
			type:{
				type:[String,Number],
				default:null
			}
		},
		components: {},
		data() {
			return {
				objInfo:{},
				loading:false
			}
		},
		created(){
			this.objInfo = this.info
		},
		watch:{
			info(x){
				this.objInfo = x
			}
		},
		methods: {
			onShare(){
				uni.share({
				    provider: "weixin",
				    scene: "WXSceneSession",
				    type: 5,
					miniProgram:{
						id:this.$global.originalId,
						path:`/pagesHome/platform/platform?invitation_code=${this.$store.state.userInfo ? this.$store.state.userInfo.invitation_code : ''}`,
						type:this.$global.environment == 'development' ? 2 : 0,
						webUrl:"https://www.baidu.com"
					},
				    title: this.info.title,
				    imageUrl:this.$global.shareImg,
				    success: (res)=> {
						setAddShare({type:this.type,id:this.objInfo.id,isErr:false}).then(()=>{
							this.objInfo.transmit ++ 
						})
				       
				    },
				    fail: function (err) {
						// console.log(JSON.stringify(err))
				    }
				});
			},
			async onOperation(type, flag) {
				if(!this.$store.getters.userInfo){
					return this.$global.getUserInfo()
				}
				if (type != 3) {
					if (this.loading) return
					this.loading = true
					try {
						var res = await setLikeCollection({
							flag: flag,
							status: type,
							id: this.objInfo.id ? this.objInfo.id :  this.type == 3  ? 1 :this.type == 4 ?  2 : '',
							type: this.type  ,// 3平台介绍 4装修攻略 11 工艺标准

						})
						this.loading = false
						if (type == 1) {
							if (flag) {
								this.objInfo.is_like = 2
								this.objInfo.like = Number(this.objInfo.like) - 1
							} else {
								this.objInfo.is_like = 1
								this.objInfo.like = Number(this.objInfo.like) + 1
							}
						} else {
							if (flag) {
								this.objInfo.is_collect = 2
								this.objInfo.collect = Number(this.objInfo.collect) -1
							} else {
								this.objInfo.is_collect = 1
								this.objInfo.collect = Number(this.objInfo.collect) + 1
							}
						}
			
					} catch {
						uni.showToast({title:'操作失败',icon:'none'})
						this.loading = false
					}
				} else {
					this.onShare()
				}
			
			},
			
		},
	}
</script>

<style scoped>
	.bottomBtn{
		width: 100%;
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		padding: 46rpx;
		background: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: space-between;
		font-size: 28rpx;
		font-family: PingFang SC, PingFang SC-Medium;
		font-weight: 500;
		text-align: center;
		color: #adadad;
		box-sizing: border-box;
	}
	.bottomBtn .row{
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.bottomBtn .row image{
		width: 48rpx;
		height: 48rpx;
		margin-right: 4rpx;
	}
	
	.row2{
		margin: 0;
		background-color: #fff;
		font-size: 28rpx;
		font-family: PingFang SC, PingFang SC-Medium;
		font-weight: 500;
		text-align: center;
		color: #adadad;
	}
	button[loading]::before {
		align-self: center
	}
	
	button {
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-item: center;
		padding: 0;
	}
	
	button::after {
		border: none;
	}
</style>
